/*
 * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. 
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. 
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. 
 * Vestibulum commodo. Ut rhoncus gravida arcu. 
 */

/**
 * 位运算
 */
public class Demo04 {

    public static void main(String[] args) {
        //异或运算 1^1=0 0^0=0 1^0=1 0^1=1
        int i1 = 0b1010;    //0 0000...1010
        int i2 = 0b1001;    //0 0000...1001
        int i3 = i1 ^ i2;   //0 0000...0011

        System.out.println(i1);
        System.out.println(i2);
        System.out.println(i3);// 3 0b11;
        System.out.println(i3 ^ i2);

        //与,并且 1&1=1 1&0=0 0&1=0 0&0=0
        i3 = i1 & i2;
        System.out.println(i3);// 0 0000...1000

        //或,或者 1|1=1 1|0=1 0|1=1 0|0=0
        i3 = i1 | i2;
        System.out.println(i3);// 0 0000...1011

        //非 ~1=0 ~0=1
        i3 = ~i1;
        System.out.println(i3);// 1 1111...0101;?-11,补码
        //原 1 0000...1011
        //反 1 1111...0100
        //补 1 1111...0101


    }
}
